// components/naviBar/index.js
import {StatusBar} from "../../utils/statusBar"
import {constant} from "../../types/constant"
const App = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    naviTitle: {
      type: String,
      value: ""
    },
    bgColor: {
      type: String,
      value: ""
    },
    isCatchBack:{
      type:Boolean,
      value:false
    },
    isHideBack:{
      type:Boolean,
      value:false
    },
    titleColor:{
      type:String,
      value:'black'
    },
    navigateParam:{
      type:String,
      value:''
    },
    isLeftTitle:{
      type:Boolean,
      value:false
    },
    isPersonPage: {
      type: Boolean,
      value: false
    } 
  },

  /**
   * 组件的初始数据
   */
  data: {
    navHeight: 0,
    cloudPic: constant.cloudIconUrl
  },

  /**
   * 组件的方法列表
   */
  methods: {
    back: function () {
      if (this.data.isPersonPage) {
        this.triggerEvent("backAction",{value:''})
        return
      }
      if(this.data.isCatchBack){
        this.triggerEvent("backAction",{value:''})
      }
      if(this.data.navigateParam != ''){
        let pages = getCurrentPages();  // 当前页的数据，可以输出来看看有什么东西
        let prevPage = pages[pages.length - 2];  // 上一页的数据，也可以输出来看看有什么东西
        prevPage.setData({
          value: this.data.navigateParam,
        })
      }
      wx.navigateBack();
    }
  },
  ready: function () {
    this.setData({
      navHeight: App.globalData.navHeight
    })
    if(this.data.bgColor=='#ffffff'){
      StatusBar.changeBlack();
    }
  }
})
